<?php

use app\models\User;
use yii\helpers\Html;
use yii\helpers\Url;
use yii\widgets\ActiveForm;

/**
 * @var yii\web\View $this
 * @var string $content
 * @var User $user
 */

$this->title = '矿大FM';

?>
<?php $this->beginPage() ?>
<!DOCTYPE html>
<html lang="<?= Yii::$app->language ?>">
<head>
    <base href="/">
    <meta charset="<?= Yii::$app->charset ?>">
    <meta name="viewport" content="width=device-width, initial-scale=1,user-scalable=no">
    <?= Html::csrfMetaTags() ?>
    <title><?= Html::encode($this->title) ?></title>
    <?php $this->head() ?>

    <!--    引入字体图表需要的css-->
    <link rel="stylesheet" href="/font-awesome-4.2.0/css/font-awesome.min.css">
    <link rel="stylesheet" href="css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" href="/css/reset.css">
    <link rel="stylesheet" type="text/css" href="/css/info.css">
</head>
<body>
<?php $this->beginBody() ?>
<div class="container-fluid">
    <div class="row title-wrap">
        <div class="col-xs-2 back">
            <a href="javascript:history.back();">
                <i class="fa fa-arrow-left" aria-hidden="true"></i>
            </a>
        </div>
        <div class="col-xs-8 main-title"><span><?=$user->user_name?></span></div>
        <div class="col-xs-2"></div>
    </div>
    <div class="clearfix"></div>
	<?php $form = ActiveForm::begin([
		'action'=> Url::to('/user/info-submit'),
		'class' => 'form form-horizontal',
	]); ?>
    <div class="content row">
        <div class="pic-wrap">
            <div class="user-pic" id="userpic">
                <img src="<?=$user->avatar?>-avatar">
                <div id="change-pic"><span id="change-icon"><i class="fa fa-refresh"></i></span><br/><span>更换头像</span></div>
				<input type="hidden" name="avatar" id="avatar" value="<?=$user->avatar ?>">
            </div>
<!--            <div id="userId"><?=$user->user_name?></div>-->
        </div>
        <div class="col-xs-10 col-xs-offset-1">
			<div class="form-group row">
				<div class="input-title">签名</div>
				<div class="inputCol">
					<label for="sign" class="label-wrap">
						<span class="pull-left"><i class="fa fa-pencil"></i></span>
						<div class="input-wrap">
							<input type="text" name="signature" id="sign" class="user-input" value="<?=$user->signature?>" value="" placeholder="请输入你的签名">
						</div>
					</label>
				</div>
			</div>
			<div class="form-group row">
				<div class="input-title">学号</div>
				<div class="inputCol">
					<label for="schid" class="label-wrap">
						<span class="pull-left"><i class="fa fa-credit-card"></i></span>
						<div class="input-wrap">
							<input type="number" name="stu_num" id="schid" class="user-input" value="<?=$user->stu_num?>" placeholder="请输入8位学号">
						</div>
					</label>
				</div>
			</div>
			<div class="form-group row">
				<div class="input-title">性别</div>
				<div class="inputCol sexCol">
					<label class="label-wrap" for="useridentity-sex">
						<span class="pull-left sexIcon"><i class="fa fa-transgender"></i></span>
						<div class="choose-sex input-wrap">
							<?= Html::dropDownList('sex', $user->sex, User::$sexArray, [
								'id'=>"useridentity-sex",
								'class'=>"form-control",
							]) ?>
						</div>
					</label>
				</div>
			</div>
        </div>
    </div>
	<?php ActiveForm::end(); ?>
</div>

<?php //$this->endBody() ?>

<script src="js/lib/jquery/jquery.min.js"></script>
<script src="js/lib/bootstrap/bootstrap.min.js"></script>
<script src="js/lib/jquery.bootstrap-growl.min.js"></script>
<script src="js/lib/qiniu/plupload.full.min.js"></script>
<script src="js/lib/qiniu/qiniu.js"></script>
<script src="js/util/ajax.js"></script>
<script src="js/util/ajax-ui.js"></script>
<script>
    var $form = $('form');
    $.ajaxUI.form($form, function () {
        $.bootstrapGrowl('信息已保存', {
            type: 'success',
            offset: {from: 'bottom', amount: 60},
            align: 'center',
            width: 'auto',
            delay: 2000,
            allow_dismiss: false,
            stackup_spacing: 10
        });
    });
    $form.find('input,select').change(function () {
        $form.trigger('submit');
    })
    var isLoading=false;
    var uploader = Qiniu.uploader({
        runtimes: 'html5,html4',
        browse_button: "userpic",
        uptoken_url: '/sundry/upload-token',
        unique_names: true,
        domain: 'http://7xss8o.com1.z0.glb.clouddn.com/',
        max_file_size: '2mb',
        max_retries: 3,
        dragdrop: true,
        chunk_size: '4mb',
        auto_start: true,
        init: {
            'FilesAdded': function(up, files) {
                if(isLoading){
                    return;
                }
                isLoading = true;
            },
            'FileUploaded': function(up, file, info) {
                var domain = up.getOption('domain');
                var res = JSON.parse(info);
                var sourceLink = domain + res.key;
                $("#avatar").val(sourceLink);
                $("#userpic img").attr('src', sourceLink+'-avatar');
				$form.trigger('submit');
            },
            'Error': function(up, err, errTip) {
                console.log(up);
                console.log(err);
                console.log(errTip);
                alert(errTip);
            },
            'UploadComplete': function() {
                //队列文件处理完毕后,处理相关的事情
                isLoading = false;
            }
        }
    });
</script>
<div style="display: none;"><script src="http://s11.cnzz.com/z_stat.php?id=1261300538&web_id=1261300538" language="JavaScript"></script></div>
</body>
</html>
<?php $this->endPage() ?>
